const Router = require('koa-router');
const response = require('../libs/result');
let router = new Router();
const _ = require('underscore');


/**
 * @api {post} /api/v1/about/checkversion  检测新版本
 * @apiDescription 检测新版本
 * @apiName checkversion
 * @apiSampleRequest /api/v1/about/checkversion
 * @apiGroup about
 * @apiVersion 1.0.0
 */
router.post('/checkversion', async ctx => {
  response(ctx, 200, ctx.config.appversion, 'appversion');
})

/**
 * @api {post} /api/v1/about/contentwebsite  获取平台相关信息
 * @apiDescription 获取平台相关信息
 * @apiName contentwebsite
 * @apiSampleRequest /api/v1/about/contentwebsite
 * @apiParam (参数) {String} ctype    ctype about_us 关于我们  loan_agreement 借款协议 agreement_terms 隐私政策协议 apiurl项目中会用到的api
 * @apiGroup about
 * @apiVersion 1.0.0
 */
router.post('/contentwebsite', async ctx => {
  let { ctype } = ctx.request.body;
  let website = await ctx.db.query(`select * from content_website where country_id=?`, [parseInt(ctx.config.country_id)])

  if (ctype == "about_us") {
    response(ctx, 200, website[0].about_us, '关于我们');
    return;
  }
  if (ctype == "loan_agreement") {
    response(ctx, 200, website[0].loan_agreement, '借款协议');
    return;
  }
  if (ctype == "agreement_terms") {
    response(ctx, 200, website[0].agreement_terms, 'useragrrment');
    return;
  }
  if (ctype == "openloan") {
    //response(ctx, 200, 0, '暂未开放');
    response(ctx, 200, 1, '');
    return;
  }
  if (ctype == "apiurl") {
    let url = {
      osstokenapi: ctx.config.osstokenapi,
      bucket: ctx.config.bucket,
      faceapi: ctx.config.faceapi
    }
    response(ctx, 200, url, 'apiurl');
    return;
  }
})

/**
 * @api {post} /api/v1/about/getnewscontenturl  获取h5资讯详情
 * @apiDescription 获取h5资讯详情
 * @apiName getnewscontenturl
 * @apiSampleRequest /api/v1/about/getnewscontenturl
 * @apiParam (参数) {String} newsid    newsid
 * @apiGroup about
 * @apiVersion 1.0.0
 */
router.post('/getnewscontenturl', async ctx => {
  response(ctx, 200, 'https://www.baidu.com', 'useragrrment');
})

module.exports = router.routes()